﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RedSand.Web.Mvc;
using RedSand.Site.Models;

namespace RedSand.Site.Controllers
{
    public class SupportController : BaseController
    {
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Manager()
        {
            return View(new ManagerModel { Title = Translate("SupportManager", "Support") });
        }

        [HttpGet, AjaxOrChildAction]
        public ActionResult List()
        {
            return PartialView(RsDataManager.GetList<SupportInfo>("SupportGetList", new { Language = LanguageCode }));
        }
        public ActionResult GetById(int Id)
        {
            return PartialView(RsDataManager.GetInfo<SupportInfo>("SupportGetInfo", "SupportID", Id));
        }
        
        [HttpGet, AjaxOrChildAction]
        public ActionResult Create()
        {
            return PartialView();
        }

        [HttpPost, AjaxOrChildAction]
        public ActionResult Create(SupportInfo info)
        {
            if (ModelState.IsValid)
            {
                info.Language = LanguageCode;
                if (RsDataManager.Save("SupportSave", info))
                {
                    AddMessage(Message.CreateSuccess);
                    return RedirectToAction("List");
                }
                return AjaxMessage(Message.CreateError);
            }
            return AjaxModelError();
        }

        [HttpGet, AjaxOrChildAction]
        public ActionResult Edit(int id)
        {
            return PartialView(RsDataManager.GetInfo<SupportInfo>("SupportGetInfo", "SupportID", id));
        }

        [HttpPost, AjaxOrChildAction]
        public ActionResult Edit(SupportInfo info)
        {
            if (ModelState.IsValid)
            {
                if (RsDataManager.Save("SupportSave", info))
                {
                    AddMessage(Message.UpdateSuccess);
                    return RedirectToAction("List");
                }
                return AjaxMessage(Message.UpdateError);
            }
            return AjaxModelError();
        }

        [AjaxOrChildAction]
        public ActionResult Delete(int id)
        {
            if (RsDataManager.Delete("SupportDelete", "SupportID", id))
            {
                AddMessage(Message.DeleteSuccess);
                return RedirectToAction("List");
            }
            return AjaxMessage(Message.DeleteError);
        }
        public ActionResult GetList()
        {
            return PartialView(RsDataManager.GetList<SupportInfo>("SupportGetList", new { Language = LanguageCode }));
        }
        [HttpGet]
        public ActionResult GetBySkypeId(string SkypeId)
        {
            return View(RsDataManager.GetInfo<SupportInfo>("SupportGetBySkypeId", new { SkypeId = SkypeId, Language = LanguageCode }));
        }
    }
}
